/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Admin.DAO;

import Admin.Model.RealEstate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author home
 */
public class RealEstateDAO {
    private Connection myCon;
    private PreparedStatement ps;
    private ResultSet rs;
    private String strCommand = "";

    public ArrayList<RealEstate> GetAll() {
        ArrayList<RealEstate> listRealEstate = new ArrayList<RealEstate>();
        RealEstate realEstate = null;
        try {

            strCommand = "select * from tbl_RealEstate";
            myCon = myConnection.getConnection();
            myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand);

            rs = ps.executeQuery();
            while (rs.next()) {
                realEstate = new RealEstate();
                realEstate.setRealEstateID(rs.getInt("RealEstateID"));
                realEstate.setRealEstateTitle(rs.getString("realEstateTitle"));
                realEstate.setCity(rs.getString("City"));
                realEstate.setStreet(rs.getString("Street"));
                realEstate.setPrice(rs.getString("Price"));
                realEstate.setNoOfBedrooms(rs.getInt("NoOfBedrooms"));
                realEstate.setNoOfBathrooms(rs.getInt("NoOfBathrooms"));
                realEstate.setRealEstateTypeID(rs.getInt("realEstateTypeID"));
                realEstate.setArea(rs.getString("area"));
                realEstate.setOrientation(rs.getString("orientation"));
                realEstate.setExtraFacilitiesAvailable(rs.getInt("ExtraFacilitiesAvailable"));
                realEstate.setModesOfTransport(rs.getString("ModesOfTransport"));
                realEstate.setWithFurniture(rs.getInt("WithFurniture"));
                realEstate.setModeOfPayment(rs.getString("ModeOfPayment"));
                realEstate.setDeposit(rs.getString("Deposit"));
                realEstate.setNegotiable(rs.getInt("Negotiable"));
                realEstate.setDescription(rs.getString("Description"));
                realEstate.setRealEstateImage(rs.getString("realEstateImage"));
                realEstate.setRealEstateStyleID(rs.getInt("realEstateStyleID"));
                realEstate.setRealEstateStatus(rs.getInt("realEstateStatus"));

                listRealEstate.add(realEstate);
            }
            return listRealEstate;
        } catch (SQLException ex) {
            Logger.getLogger(RealEstate.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            myConnection.closeConnection(myCon, ps, rs);
        }
        return listRealEstate;
    }
    public RealEstate GetByID(int RealEstateID) {
        RealEstate realEstate = null;
        try {

            strCommand = "select * from tbl_RealEstate where RealEstateID=?";
            myCon = myConnection.getConnection();
            myConnection.getConnection();
            ps = myCon.prepareStatement(strCommand);
            ps.setInt(1, RealEstateID);
            rs = ps.executeQuery();
            while (rs.next()) {
                realEstate = new RealEstate();
                realEstate.setRealEstateID(rs.getInt("RealEstateID"));
                realEstate.setRealEstateTitle(rs.getString("realEstateTitle"));
                realEstate.setCity(rs.getString("City"));
                realEstate.setStreet(rs.getString("Street"));
                realEstate.setPrice(rs.getString("Price"));
                realEstate.setNoOfBedrooms(rs.getInt("NoOfBedrooms"));
                realEstate.setNoOfBathrooms(rs.getInt("NoOfBathrooms"));
                realEstate.setRealEstateTypeID(rs.getInt("realEstateTypeID"));
                realEstate.setArea(rs.getString("area"));
                realEstate.setOrientation(rs.getString("orientation"));
                realEstate.setExtraFacilitiesAvailable(rs.getInt("ExtraFacilitiesAvailable"));
                realEstate.setModesOfTransport(rs.getString("ModesOfTransport"));
                realEstate.setWithFurniture(rs.getInt("WithFurniture"));
                realEstate.setModeOfPayment(rs.getString("ModeOfPayment"));
                realEstate.setDeposit(rs.getString("Deposit"));
                realEstate.setNegotiable(rs.getInt("Negotiable"));
                realEstate.setDescription(rs.getString("Description"));
                realEstate.setRealEstateImage(rs.getString("realEstateImage"));
                realEstate.setRealEstateStyleID(rs.getInt("realEstateStyleID"));
                realEstate.setRealEstateStatus(rs.getInt("realEstateStatus"));

            }
            return realEstate;
        } catch (SQLException ex) {
            Logger.getLogger(RealEstate.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            myConnection.closeConnection(myCon, ps, rs);
        }
        return realEstate;
    }
}
